package com.example.controller;

import com.example.model.pojo.Result;
import com.example.service.ProblemService;
import com.example.service.UserInfoService;
import com.example.util.FaceRecognitionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description //TODO
 * @Date 2022/9/22 14:21
 * @Author lonng
 **/
@ResponseBody
@Controller
@RequestMapping("interview")
public class InterviewController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private FaceRecognitionUtil faceRecognitionUtil;
    @Autowired
    private ProblemService problemService;
    @PostMapping("/add")
    public Result startInterview(@RequestParam("newImg")String newImg, HttpServletRequest request){
//        System.out.println(newImg);
        String uImg="D:\\nginx-1.22.0\\nginx-1.22.0\\html\\cattle-and-horses-oj-html\\image\\"+userInfoService.findAllByUUid(Integer.valueOf(String.valueOf(request.getAttribute("uid")))).getAvatar();
        int rec=faceRecognitionUtil.SimilarityRate(newImg,uImg);
        System.out.println(rec);
        if(rec<90){
            return new Result("200","sorry，请重试");
        }else{
//            System.out.println(problemNum.num());
            double problemId=Math.random()*problemService.getCount()+1;
//            System.out.println(Integer.valueOf((int) problemId));
            return new Result("200","登陆成功","http://localhost:70/cattle-and-horses-oj-html/html/doproblem.html?id="+Integer.valueOf((int) problemId));
        }
    }

}
